home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / fmodla13.zip / TALK.ZIP / TICKER.MOD < prev    next >
Text File  |  1987-10-18  |  2KB  |  63 lines

  1. IMPLEMENTATION MODULE Ticker;
  2.  
  3. (* (C) Copyright 1987 Fitted Software Tools. All rights reserved.
  4.  
  5.     This module is part of the example multitasking communications program
  6.     provided with the Fitted Software Tools' Modula-2 development system.
  7.  
  8.     Registered users may use this program as is, or they may modify it to
  9.     suit their needs or as an exercise.
  10.  
  11.     If you develop interesting derivatives of this program and would like
  12.     to share it with others, we encourage you to upload a copy to our BBS.
  13. *)
  14.  
  15.  
  16. FROM SYSTEM     IMPORT ASSEMBLER, ADDRESS;
  17. FROM System     IMPORT TermProcedure, GetVector, SetVector, ResetVector;
  18.  
  19. (* $S- *)
  20.  
  21. VAR
  22.     ClockTick       :ADDRESS;
  23.  
  24.  
  25. PROCEDURE Tick;
  26. (*
  27.     Timer tick ISR
  28.  
  29.     This ISR could have been implemented as an IO process, but that
  30.     would be boring!
  31.  
  32.     This serves as an example on how to write interrupt routines that
  33.     are attached to the interrupt vectors with some help from System.
  34. *)
  35. BEGIN
  36.     ASM
  37.         STI
  38.         PUSH    DS
  39.         MOV     DS, CS:[0]
  40.         INC     Ticks
  41.         PUSHF                       (* Chain interrupt *)
  42.         CALL    FAR ClockTick       (* Invoke the system's clock ISR *)
  43.         POP     DS
  44.         IRET
  45.     END;
  46. END Tick;
  47.  
  48.  
  49. PROCEDURE StopClock;
  50. BEGIN
  51.     (* restore the original clock ISR *)
  52.     ResetVector( 8, ClockTick );
  53. END StopClock;
  54.  
  55.  
  56. BEGIN
  57.     Ticks := 0;
  58.     GetVector( 8, ClockTick );      (* save system's clock ISR *)
  59.     TermProcedure( StopClock );     (* set procedure to restore system's ISR *)
  60.                                     (* on program termination *)
  61.     SetVector( 8, Tick );           (* install our own clock ISR *)
  62.  
  63. END Ticker.